<?php $this->load->view('layout/header'); ?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <h3 class="page-title">旅游商品管理<small> 产品属性</small></h3>
            <?php echo breadcrumb(array('tourismgoods/grid' => '旅游产品')); ?>
        </div>
    </div>
    <div class="alert alert-error" style="display:none;">
        <button data-dismiss="alert" class="close"></button>
        <a href="javascript:;" class="glyphicons no-js remove_2"><i></i><p></p></a>
    </div>
    <div class="row-fluid">
        <div class="span12">
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-plus-sign">添加属性规格</i></div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <form class="form-horizontal tourismgoods-form">
                        <div class="control-group">
                            <label class="control-label"><em>* </em>所属类别</label>
                            <div class="controls">
                                <input type="hidden" name="category_id" value="<?php echo $category_id ?>">
                                <input type="text" value="<?php echo $cate ?>" class="m-wrap large" readonly="readonly">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><em>* </em>属性名称</label>
                            <div class="controls">
                                <input type="text" name="attr_name" class="m-wrap large required" />
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><em>* </em>属性规格</label>
                            <div class="controls big-attr">
                                <p class="attribute"><input type="text" name="attribute_value[]" class="m-wrap large required" /></p>
                            </div>
                        </div>
                        <div class="form-actions">
                            <button class="btn green" type="submit"><i class="icon-ok"></i> 保存</button>
                            <a class="btn yellow add-attr" type="button">添加</a>
                            <a href="<?php echo base_url('tourismgoodscategoryattribute/grid/'.$category_id) ?>">
                                <button class="btn" type="button">返回</button>
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

$('.form-actions').delegate('.add-attr','click',function(event){  //属性的增加
    var line = '<p class="attribute"><input type="text" name="attribute_value[]" class="m-wrap large required"/><a class="btn delete-attr">删除</a></p>';
    $('.big-attr').append(line);
}) 

$('.big-attr').delegate('.delete-attr','click',function(event){
	$(this).parent().remove();
})

//提交验证
$('form.tourismgoods-form').submit(function () {
    return false;
}).validate({
    submitHandler: function (f) {
        $.ajax({
            type: 'post',
            async: true,
            dataType: 'json',
            beforeSend:function(){
                $('button[type="submit"]').text('正在保存中').prop('disabled',true);
            },
            url: hostUrl() + '/tourismgoodscategoryattribute/addPost',
            data: $('form.tourismgoods-form').serialize(),
            success: function (data) {
                if (data.status) {
                    $('.alert-error').hide();
                    window.location.href = data.messages;
                } else {
                    $('.alert-error').show();
                    $('.alert-error .remove_2 p').html(data.messages);
                    var body = (window.opera) ? (document.compatMode == 'CSS1Compat' ? $('html') : $('body')) : $('html,body');
                    body.animate({scrollTop: $('.page-container').offset().top}, 1000);
                    $('button[type="submit"]').text('请重新保存').prop('disabled',false);
                }
            }
        });
    }
});
</script>
<?php $this->load->view('layout/footer'); ?>